package com.haoxin.ai_course.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import lombok.Data;

/**
 * 
 * 微信小程序
 * 
 */

@Configuration

@ConditionalOnClass(WxMaService.class)

@ConfigurationProperties(prefix = "wechat.miniapp")
@Data
public class WxMaConfiguration {

	/**
	 * 
	 * 设置微信小程序的appId
	 * 
	 */

	private String appId;

	/**
	 * 
	 * 设置微信小程序的Secret
	 * 
	 */

	private String appSecret;

	@Bean

	@ConditionalOnMissingBean(WxMaService.class)

	public WxMaService wxMaService() {

		WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();

		config.setAppid(this.getAppId());

		config.setSecret(this.getAppSecret());

		WxMaService service = new WxMaServiceImpl();

		service.setWxMaConfig(config);

		return service;

	}

}
